package com.example.finaltool.controller;

import com.example.finaltool.model.Result;
import com.example.finaltool.service.CmmFunctionConfigService;
import com.example.finaltool.service.InfoService;
import com.example.finaltool.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author dengbw
 * @date 2021/8/11 3:00 下午
 */
@Api(tags = "1.部署工具", value = "deploy")
@Slf4j
@RestController
@RequestMapping("deploy")
public class DeployController {
    CmmFunctionConfigService cmmFunctionConfigService;
    InfoService infoService;
    SysUserService sysUserService;

    @Autowired
    public DeployController(CmmFunctionConfigService cmmFunctionConfigService,
                            InfoService infoService,
                            SysUserService sysUserService) {
        this.cmmFunctionConfigService = cmmFunctionConfigService;
        this.infoService = infoService;
        this.sysUserService = sysUserService;
    }

    @ApiOperation("复制资讯，先调用一下补全subId的接口")
    @GetMapping("info/copy/{corpId}/{appKey}/{appSecret}")
    public Result<List<String>> copyInfo(@PathVariable("corpId") String corpId,
                                         @PathVariable("appKey") String appKey,
                                         @PathVariable("appSecret") String appSecret) {
        return infoService.copyInfo(corpId, appKey, appSecret);
    }

    @ApiOperation("补全subId")
    @GetMapping("info/fill/{corpId}/{appKey}/{appSecret}")
    public Result<Boolean> fillSubId(@PathVariable("corpId") String corpId,
                            @PathVariable("appKey") String appKey,
                            @PathVariable("appSecret") String appSecret) {
        return infoService.fillSubIds(corpId, appKey, appSecret);
    }

    @ApiOperation(value = "更新用户功能", notes = "当发现功能只剩更多功能的时候用这个")
    @GetMapping("menu/update/{appKey}/{appSecret}")
    public Result<List<String>> updateMenu(@PathVariable("appKey") String appKey,
                             @PathVariable("appSecret") String appSecret) {
        return sysUserService.updateMenu(appKey, appSecret);
    }

    @ApiOperation(value = "修复工作台为空")
    @GetMapping("menu/fix/{corpIdd}")
    public Result<Integer> fixMenu(@PathVariable("corpIdd") String corpId) {
        return Result.success(sysUserService.fixMenu(corpId));
    }
}
